package br.com.marcio;

import java.awt.GraphicsDevice;
import java.awt.GraphicsDevice.WindowTranslucency;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class TranslucentWindowDemo extends JFrame {

	public TranslucentWindowDemo() {
		super("TranslucentWindow");
		setLayout(new GridBagLayout());

		setSize(300,200);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		//Add a sample button.
		add(new JButton("I am a Button"));
    }

    public static void main(String[] args) {
    	// Determine if the GraphicsDevice supports translucency.
    	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    	GraphicsDevice gd = ge.getDefaultScreenDevice();

    	//If translucent windows aren't supported, exit.
    	if (!gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
    		System.err.println("Translucency is not supported");
    		System.exit(0);
    	}

    	JFrame.setDefaultLookAndFeelDecorated(true);

    	// Create the GUI on the event-dispatching thread
    	SwingUtilities.invokeLater(new Runnable() {
    		public void run() {
    			TranslucentWindowDemo tw = new TranslucentWindowDemo();

    			// Set the window to 55% opaque (45% translucent).
    			tw.setOpacity(0.55f);

    			// Display the window.
    			tw.setVisible(true);
    		}
    	});
	}
}